package com.example.courseapp.activity;

import static android.text.TextUtils.isEmpty;
import static com.example.courseapp.activity.RecordActivity2.filterLastSevenDays;
import static com.example.courseapp.activity.RecordActivity2.getBMI;
import static com.example.courseapp.activity.RecordActivity2.validateBMI;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.courseapp.R;
import com.example.courseapp.RetrofitHelper;
import com.example.courseapp.bean.ChildInformation;
import com.example.courseapp.bean.ChildSportRecords;
import com.example.courseapp.bean.NewFoodInfo;
import com.example.courseapp.bean.NewRecommendFoodInfo;
import com.example.courseapp.net.CourseService;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RecordActivity extends AppCompatActivity {
    /*推荐食谱*/

    List<String> foodL = new ArrayList<>();
    CourseService service;
    TextView textView;
    Integer childID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_record);
        childID = getIntent().getIntExtra("childID", 0);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        findViewById(R.id.back).setOnClickListener(v -> {
            finish();
        });
        service = RetrofitHelper.getInstance().createService(CourseService.class);

        getRecommend();
        textView = findViewById(R.id.myContent);
    }

    private void defaultData() {


        foodL.add("早餐：\n" +
                "\n" +
                "蓝莓坚果燕麦碗\n" +
                "一杯花草茶\n" +
                "上午小吃：\n" +
                "\n" +
                "鲜花沙拉（蜜糖柠檬醋汁）\n" +
                "小杯蔬菜汤\n" +
                "午餐：\n" +
                "\n" +
                "花朵三文鱼寿司卷\n" +
                "紫薯汤\n" +
                "下午茶：\n" +
                "\n" +
                "菊花茶\n" +
                "花瓣小饼干\n" +
                "晚餐：\n" +
                "\n" +
                "玫瑰花瓜莴苣沙拉\n" +
                "紫胡椒蘑菇扇贝");
        foodL.add("早餐：\n" +
                "\n" +
                "红色草莓蓝莓酸奶杯\n" +
                "绿茶\n" +
                "上午小吃：\n" +
                "\n" +
                "橙色胡萝卜小吃\n" +
                "鲜橙汁\n" +
                "午餐：\n" +
                "\n" +
                "黄色咖喱鸡配香米\n" +
                "菠菜蕃茄沙拉\n" +
                "下午茶：\n" +
                "\n" +
                "蓝色蓝莓冰沙\n" +
                "龙井绿茶\n" +
                "晚餐：\n" +
                "\n" +
                "紫色紫甘蓝鱼柳卷\n" +
                "红薯糙米饭");
        foodL.add("早餐：\n" +
                "\n" +
                "墨西哥风味玉米饼卷，搭配鳄梨和蕃茄\n" +
                "阿拉伯式清晨咖啡\n" +
                "上午小吃：\n" +
                "\n" +
                "日本寿司卷\n" +
                "椰奶芒果冰沙\n" +
                "午餐：\n" +
                "\n" +
                "意大利风味披萨，薄饼上有意大利香肠和新鲜羊奶酪\n" +
                "希腊沙拉\n" +
                "下午茶：\n" +
                "\n" +
                "英式下午茶，包括茶和经典的英式饼干\n" +
                "晚餐：\n" +
                "\n" +
                "摩洛哥风味烤羊肉，搭配蔬菜塔吉锅和库斯库斯\n" +
                "巴西香蕉糕点作为甜点");


        Random random = new Random();
        textView.setText(foodL.get(random.nextInt(3)));
    }

    private void getRecommend() {
        service.getRecommend(childID).enqueue(new Callback<NewRecommendFoodInfo>() {
            @Override
            public void onResponse(Call<NewRecommendFoodInfo> call, Response<NewRecommendFoodInfo> response) {

                NewRecommendFoodInfo data = response.body();
                if (!isEmpty(data.getSuggest())) {
                    textView.append(data.getSuggest());
                }

            }

            @Override
            public void onFailure(Call<NewRecommendFoodInfo> call, Throwable t) {

            }
        });
    }
}